//
//  JobTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/8.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "JobTableViewCell.h"


@interface JobTableViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, strong)UIImageView * oneImageView;
@property (nonatomic, strong)UIImageView * twoImageView;
@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, weak)UIButton * infoButton;
@property (nonatomic, weak)UILabel * bottomLabel;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)UIView * bottomView;

@end

@implementation JobTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setModel:(HomeJobListModel *)model{
    
    _model = model;
    
    NSString * money = [NSString stringWithFormat:@"%@",model.salary];
    
    self.oneLabel.text = money;
    self.twoLabel.text = model.trade;
    self.threeLabel.text = model.education;
    self.bottomLabel.text = model.company;
    self.titleLabel.text = model.position;
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.text = @"阿斯蒂芬哪怕是萨拉热地方";
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    self.oneLabel = [self setupLabelWith:@"面议"];
    [self.contentView addSubview:self.oneLabel];
    
    self.twoLabel = [self setupLabelWith:@"不限"];
    [self.contentView addSubview:self.twoLabel];
    
    self.threeLabel = [self setupLabelWith:@"不限"];
    [self.contentView addSubview:self.threeLabel];
    
    self.oneImageView = [self setupImageViewWith:@"gongzuo"];
    [self.contentView addSubview:self.oneImageView];
    
    self.twoImageView = [self setupImageViewWith:@"xueli"];
    [self.contentView addSubview:self.twoImageView];
    
    UIButton * infoButton = [UIButton new];
    
    [infoButton setTitle:@"详情" forState:UIControlStateNormal];
    [infoButton setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    [infoButton setBackgroundColor:MAINCOLOR];
//    [infoButton addTarget:self action:@selector(clickInfoButton) forControlEvents:UIControlEventTouchUpInside
//     ];
    infoButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.infoButton = infoButton;
    
    [self.contentView addSubview:self.infoButton];
    
    self.lineView = [self setupLineView];
    [self.contentView addSubview:self.lineView];
    
    self.bottomView = [self setupLineView];
    [self.contentView addSubview:self.bottomView];
    
    
    UILabel * bottomLabel = [UILabel new];
    
    bottomLabel.textColor = [UIColor darkGrayColor];
    bottomLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    bottomLabel.text = @"阿斯蒂芬哪怕是萨拉热地方";
    
    self.bottomLabel = bottomLabel;
    
    [self.contentView addSubview:self.bottomLabel];
}


- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(15 * SCREENH6);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.oneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.oneLabel);
        make.width.mas_equalTo(14 * SCREENH6);
        make.height.mas_equalTo(12 * SCREENH6);
        make.leading.mas_equalTo(self.oneLabel.mas_trailing).offset(20 * SCREENH6);
    }];
    
    [self.twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneImageView.mas_trailing).offset(3 * SCREENH6);
        make.centerY.mas_equalTo(self.oneImageView);
    }];
    
    [self.twoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.width.mas_equalTo(self.oneImageView);
        make.leading.mas_equalTo(self.twoLabel.mas_trailing).offset(20 * SCREENH6);
    }];
    
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.twoImageView.mas_trailing).offset(3 * SCREENH6);
        make.centerY.mas_equalTo(self.twoImageView);
    }];
    
    [self.infoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.threeLabel).offset(-10 * SCREENH6);
        make.width.mas_equalTo(50 * SCREENH6);
        make.height.mas_equalTo(25 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1 * SCREENH6);
        make.leading.mas_equalTo(self.oneLabel);
        make.trailing.mas_equalTo(self.infoButton);
        make.top.mas_equalTo(self.oneImageView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneLabel);
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(3 * SCREENH6);
    }];
}


- (void)clickInfoButton{
    
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToJobInfo" object:nil];
}


- (UIImageView *)setupImageViewWith:(NSString *)string{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.backgroundColor = WHITE_COLOR;
    imageView.image = ImageNamed(string);
    
    return imageView;
}


- (UILabel *)setupLabelWith:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.textColor = [UIColor redColor];
    label.text = string;
    label.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    return label;
}


- (UIView *)setupLineView{
    
    UIView * view = [UIView new];
    
    view.backgroundColor = ColorWithRGB(0xE6E6E6);
    
    return view;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
